package org.example.synchronizeddemo;

/**
 * 类锁示例1 static形式
 */
public class synchronizedClassClass5 implements Runnable {


    @Override
    public void run() {
        method();
    }


    public void method() {
        synchronized (synchronizedClassClass5.class) {
            System.out.println("我是对象锁的代码块形式，我叫：" + Thread.currentThread().getName());
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "运行结束");
        }
    }

    public static void main(String[] args) {
        synchronizedClassClass5 syn = new synchronizedClassClass5();
        Thread thread1 = new Thread(syn);
        Thread thread2 = new Thread(syn);
        thread1.start();
        thread2.start();
        while (thread1.isAlive() || thread2.isAlive()) {

        }

        System.out.println("结束");
    }

}
